package jsyf.oa.web.report.reportCommon;

import com.alibaba.fastjson.JSONObject;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import jsyf.com.util.BaseUtils;
import jsyf.com.util.ResponseUtils;
import jsyf.oa.facade.report.reportCommon.BaiDuMapAPIFacade;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Created by jjx on 2018/5/14.
 */
@Api(value = "百度地图测距", description = "百度地图测距")
@Controller
@RequestMapping("/baiduDistance")
public class BaiDuMapAPIController {
    @Resource
    private BaiDuMapAPIFacade baiDuMapAPIFacade;

    @ResponseBody
    @RequestMapping(value = "/getDistanceByLatAndLng.json", method = RequestMethod.POST)
    @ApiOperation(
            value = "百度地图测距",
            notes = "百度地图测距",
            httpMethod = "POST",
            produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParam(name = "jsonData", value = "{lat1:'38.84124647',lng1:'100.82616536',lat2:'38.92687744140625',lng2:'100.46052978515625'}", dataType = "String", paramType = "body")
    public void getDistanceByLatAndLng(HttpServletRequest request, HttpServletResponse response, @RequestBody String jsonData) {
        JSONObject records = this.baiDuMapAPIFacade.getDistanceByLatAndLng(jsonData);
        ResponseUtils.putJsonResponse(response, BaseUtils.succsessArrHourTimeRespond(records));
    }
}
